module.exports = app => {
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
  
    const Category = app.model.define('category', {
        id: {
            type: INTEGER(20),
            primaryKey: true,
            autoIncrement: true,
          },
          pid: {
            type: INTEGER(1),
            allowNull: false,
            defaultValue: 0,
            comment: "上级栏目id",
          },
          type: {
            type: INTEGER(1),
            allowNull: false,
            defaultValue: 1,
            comment: "栏目类型 1文章 2图片 3单页",
          },
          title: {
            type: STRING(30),
            allowNull: false,
            defaultValue: "",
            comment: "栏目名称",
          },
          thumb: {
            type: STRING(1000),
            allowNull: true,
            defaultValue: "",
            comment: "栏目图片",
          },
          keywords: {
            type: STRING(80),
            allowNull: true,
            defaultValue: "",
            comment: "关键词",
          },
          description: {
            type: STRING(255),
            allowNull: true,
            defaultValue: "",
            comment: "描述",
          },
          islink: {
            type: INTEGER(1),
            allowNull: true,
            defaultValue: 0,
            comment: "是否外链 0否 1是",
          },
          url: {
            type: STRING(255),
            allowNull: true,
            defaultValue: "",
            comment: "外链网址",
          },
          posid: {
            type: INTEGER(1),
            allowNull: true,
            defaultValue: 0,
            comment: "推荐位 1焦点 2头条 3推荐",
          },
          order: {
            type: INTEGER(60),
            allowNull: true,
            defaultValue: 0,
            comment: "排序",
          },
          status: {
            type: INTEGER(1),
            allowNull: false,
            defaultValue: 1,
            comment: "状态 0取消 1正常",
          }, 
        created_time: {
          type:DATE,
          get(){
             return app.formatTime(this.getDataValue('created_time'))
          }
        },
        updated_time: DATE,
      });
  
    // 关联关系
    Category.associate = function (){
        app.model.Category.hasMany(app.model.Article, {foreignKey: 'cateId', targetKey: 'id'});
    }
  
    return Category;
  };